﻿/*
==============================================================================
//物品查询管理 页面控制层代码。
==============================================================================
*/
(function ($) {

    if (!window.platform) { window.platform = new Object(); }
    if (!window.platform.StockQueryManage) { window.platform.StockQueryManage = new Object(); }

    window.platform.StockQueryManage.initPage = function (createFunction, editFunction, removeFunction) {

        var _bindQueryButtonEvent = function () {
            $("#aquery", "#queryFm").bind("click", function () {
                var fm = $('#queryFm').serialize();
                $('#dg').datagrid('load', { model: fm });
            });
        };

        var _bindToolBarButtonEvent = function () {
           

            $("#areload", "#toolbar").bind("click", function () {
                _reloadGoods();
            });
            $("#ashow", "#toolbar").bind("click", function () {
                _showGoods();
            });
            $("#aexportall", "#toolbar").bind("click", function () {
                $('#dg').datagrid("exportRows", { type: "2", url: "/StockQuery/GoodsAllJson" });
            });
            $("#aexport", "#toolbar").bind("click", function () {
                $('#dg').datagrid("exportRows", { type: "1"});
            });
            $("#aclose", "#tb").bind("click", function () {

                $('#dd').dialog('close');


            });
        };

        var _goodsDataGridInit = function () {
            var options = {
                singleSelect: true,
                checkOnSelect: false,
                selectOnCheck: false,
                fit: true,
                border: false,
                rownumbers: true,
                nowrap: true,
                striped: true,
                remoteSort: false,
                pageSize: 10,
                pageList:[10,30,80,100],
                url: "/StockQuery/GoodsJson",
                queryParams: {model: $('#queryFm').serialize() },
                idField: "ID",
                frozenColumns: [[

                      { field: 'goodsClassName', title: '分类名称', width: 120, align: 'center', sortable: true },

                      { field: 'Name', title: '物品名称', width: 150, align: 'center', sortable: true },
                ]],
                columns: [[
                     { field: 'Code', title: '物品编码', width: 80, align: 'center', sortable: true },
                   { field: 'Inventory', title: '库存数量', width: 80, align: 'center', sortable: true },
                   { field: 'AverageAfterTaxPrice', title: '税后单价', width: 80, align: 'center', sortable: true },
                   { field: 'AveragePerPrice', title: '单价', width: 80, align: 'center', sortable: true },
                   { field: 'Unit', title: '单位', width: 80, align: 'center', sortable: true },
                     { field: 'SortNumber', title: '排序号', width: 80, align: 'center', sortable: true },
                      { field: 'Des', title: '物品描述', width: 180, align: 'center', sortable: true },
                   { field: 'Remark', title: '备注', width: 200, align: 'center' }

                ]],
                pagination: true,

                toolbar: "#toolbar",
                onDblClickRow: function (rowIndex, rowData) {
                    if (editFunction) {
                        _showGoods(rowData);
                    }
                }

            };

            $("#dg").datagrid(options);
        };



        _bindQueryButtonEvent();
        _bindToolBarButtonEvent();
        _goodsDataGridInit();
    };



   

    _showGoods = function (row) {
        row = row ? row : $("#dg").datagrid("getSelected");

        if (row) {
            $('#dd').dialog({
                title: '查看物品',
                width: 690,
                height: 400,
                closed: false,
                cache: false,
                resizable: true,
                href: '/StockQuery/StockView?id=' + row.ID,
                modal: true,
                buttons: '#tb'


            });
        }
        else {
            $.messager.alert("警告提醒", "请选择一行");
        }
    };

   

    _reloadGoods = function () {
        $('#dg').datagrid('clearChecked');
        $('#dg').datagrid('clearSelections');
        $('#dg').datagrid('reload');
    };

   

    




})(jQuery);